#!/usr/bin/python
# -*- coding: UTF-8 -*-

'''
lambda： 当函数题非常简单，可以使用 lambda 来定义匿名函数
格式： lambda 参数： 返回值表达式
'''


# def add_1(k):
#     return k + 1


# a1 = add_1(1)
# print(a1)
# a2 = lambda k: k + 1
# print(a2(1))

# 求x，y的最大值
# z = lambda x, y: x if x > y else y
# print(z(1, 3))
# print(z(5, 2))

# 递归函数
# 1+2+3+...+n = n*(n+1)/2
# def factorial(n):
# sum_ = 0
# for i in range(1, 101):
#     sum_ += i
#
# print(sum_)


# sum_ = lambda n: n * (n + 1) // 2
# print(sum_(100))

# def sum_n(n):
#     if n == 1:
#         return 1  # 递归出口
#     else:
#         return n + sum_n(n - 1)  # 递归调用
#
#
# print(sum_n(100))

# 阶乘
# def factorial(n):
#     if n == 1:
#         return 1
#     else:
#         return n * factorial(n - 1)
#
#
# print(factorial(5))

# 改用 lambda
# factorial = lambda n: 1 if n == 1 else n * factorial(n - 1)
# print(factorial(5))

# 1 1 2 3 5 8 13 21
fib = lambda n: 1 if n == 1 or n == 2 else fib(n - 1) + fib(n - 2)
print(fib(10))
